package com.wangsh.userscenter.head.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.wangsh.userscenter.common.controller.BaseController;
import com.wangsh.userscenter.service.users.pojo.AUsers;

/**
 * 拦截器
 * @author wangsh_sxt
 *
 */
@Component("authInterceptor")
public class AuthInterceptor extends BaseController implements HandlerInterceptor
{
	/**
	 * 执行方法之前
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		/*ConstatFinalUtil.SYS_LOG.info("执行方法之前拦截:obj:{}",handler);*/
		HttpSession session = request.getSession();
		
		/* 获取用户对象 */
		AUsers users = (AUsers) this.findObjfromSession(request, "1");
		if(users == null)
		{
			this.info = "请先登陆" ; 
			session.setAttribute("info", info);
			response.sendRedirect(request.getContextPath() + "/login.html");
			return false ;
		}
		return true;
	}
	
	/**
	 * 
	 */
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception
	{
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 执行方法之后
	 */
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception
	{
		// TODO Auto-generated method stub
		
	}

}
